//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//  NotificationChannelListAbsoluteTime.cs
//    
// Abstract:
//
//  A list of notification channels with an absolute reminder time.
//  
//--

using System;
using System.Collections.Generic;

namespace Microsoft.EnhancedReminders
{
    /// <summary>
    /// Represents a list of notification channels with an absolute reminder time.
    /// </summary>
    [Serializable()]
    public sealed class NotificationChannelListAbsoluteTime : NotificationChannelList
    {
        private DateTime _absoluteTime;

        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="channelList">Channel list to copy</param>
        public NotificationChannelListAbsoluteTime(NotificationChannelListAbsoluteTime channelList)
            : base(channelList)
        {
            _absoluteTime = channelList._absoluteTime;
        }

        /// <summary>
        /// Ctor.  Populates the list of channels from a given (master) list of channels.
        /// </summary>
        /// <param name="channels">The master list of channels to initialize from.</param>
        public NotificationChannelListAbsoluteTime(IEnumerable<NotificationChannel> channels)
            : base(channels)
        {
        }

        /// <summary>
        /// Ctor.  Populates the list of channels from a given (master) list of channels and 
        /// an absolute time.
        /// </summary>
        /// <param name="channels">The master list of channels to initialize from.</param>
        /// <param name="absoluteTime">The absolute time.</param>
        public NotificationChannelListAbsoluteTime(IEnumerable<NotificationChannel> channels, DateTime absoluteTime)
            : base(channels)
        {
            _absoluteTime = absoluteTime;
        }

        /// <summary>
        /// Creates a copy of a channel list instance.
        /// </summary>
        /// <returns></returns>
        public override NotificationChannelList Copy()
        {
            return new NotificationChannelListAbsoluteTime(Channels, AbsoluteTime);
        }

        /// <summary>
        /// The actual time of day on which to send a notification.  Only the
        /// hours/minutes part of the DateTime is used.
        /// </summary>
        public DateTime AbsoluteTime
        {
            get
            {
                return _absoluteTime;
            }
            set
            {
                _absoluteTime = value;
            }
        }

        /// <summary>
        /// Determines if the specified channel list is equivalent to this channel list.
        /// </summary>
        /// <param name="channelList">Channel list to compare against</param>
        /// <remarks>
        /// This method verifies that the channel lists have the same enabled channel references and in the same order.
        /// It also verifies that the time fields are the same.
        /// </remarks>
        /// <returns>
        /// True if the channel lists are equivalent; false otherwise
        /// </returns>
        public override bool Equals(NotificationChannelList channelList)
        {
            if (!base.Equals(channelList))
            {
                return false;
            }

            NotificationChannelListAbsoluteTime channelListAbsoluteTime = channelList as NotificationChannelListAbsoluteTime;

            // Check that the specified channel list is of the correct type
            if (channelListAbsoluteTime == null)
            {
                return false;
            }

            return _absoluteTime == channelListAbsoluteTime._absoluteTime;
        }

        /// <summary>
        /// Indicates if any of the channels in this list is enabled.
        /// </summary>
        public override bool IsEnabled
        {
            get
            {
                return _absoluteTime.Ticks > 0 && base.IsEnabled;
            }
        }
    }
}
